cmake_minimum_required(VERSION 3.22)
project(rocket)

set(CMAKE_CXX_STANDARD 17)
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wall")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)  # 设置可执行文件生成位置
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

find_library(TINYXML NAMES libtinyxml.so)

# find_package 进入搜索路径（可能是/usr/local/share）找到XXXConfig.cmake文件并执行 设置相关变量方便使用
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(LIB_SRC
        rocket/common/config.cpp
        rocket/common/log.cpp
        rocket/common/run_time.cpp
        rocket/common/util.cpp
        rocket/net/eventloop.cpp
        rocket/net/fdevent.cpp
        rocket/net/wakeup_fd_event.cpp
        rocket/xml/tinystr.cpp
        rocket/xml/tinyxmlerror.cpp
        rocket/xml/tinyxmlparser.cpp
        rocket/xml/tinyxml.cpp
        rocket/net/timer.cpp
        rocket/net/timer_event.cpp
        rocket/net/io_thread.cpp
        rocket/net/io_thread_group.cpp
        rocket/tcp/tcp_buffer.cpp
        rocket/tcp/net_addr.cpp
        rocket/tcp/tcp_acceptor.cpp
        rocket/tcp/tcp_server.cpp
        rocket/tcp/tcp_connection.cpp
        rocket/net/fdevent_group.cpp
        rocket/tcp/tcp_client.cpp
        rocket/coder/tinypb_coder.cpp
        rocket/coder/tinypb_protocol.cpp
        rocket/rpc/rpc_dispatcher.cpp
        rocket/rpc/rpc_controller.cpp
        rocket/rpc/rpc_channel.cpp)

add_library(rocket SHARED ${LIB_SRC})

add_executable(test_eventloop test/test_eventloop.cpp)
target_link_libraries(test_eventloop rocket ${Protobuf_LIBRARIES})

add_executable(test_log test/test_log.cpp)
target_link_libraries(test_log rocket ${Protobuf_LIBRARIES})

add_executable(test_tcp test/test_server.cpp)
target_link_libraries(test_tcp rocket ${Protobuf_LIBRARIES})

add_executable(test_client test/test_client.cpp)
target_link_libraries(test_client rocket ${Protobuf_LIBRARIES})

add_executable(test_rpc_server test/test_rpc_server.cpp)
target_sources(test_rpc_server PUBLIC test/order.pb.cc)  #链接cpp文件
target_link_libraries(test_rpc_server rocket ${Protobuf_LIBRARIES})

add_executable(test_rpc_client test/test_rpc_client.cpp)
target_sources(test_rpc_client PUBLIC test/order.pb.cc)  #链接cpp文件
target_link_libraries(test_rpc_client rocket ${Protobuf_LIBRARIES})
